<template>
  <div class="add-form">
    <el-dialog :title="titleInfo.text+titleInfo.pageTitle" :visible.sync="dialogFormVisible">
      <el-form
        :rules="ruleInline"
        ref="dataForm"
        :model="formBase"
        label-position="center"
        label-width="0"

        style=""
      >
        <el-form-item label="" prop="auditMind">
          <el-input
            type="textarea"
            :autosize="{ minRows: 6, maxRows: 6}"
            placeholder="请输入审核意见"
            v-model="formBase.auditMind"
          ></el-input>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button style="border-radius:20px;color: #FFFFFF;" type="primary" @click="agree()">通过</el-button>
        <el-button style="background-color:#F56C6C;border-radius:20px;color: #FFFFFF;"  @click="refuse('202001')">拒绝</el-button>
      </div>
    </el-dialog>
  </div>
</template>
<script>
import { approve } from '@/api/xczx/courses'
export default {
  name: 'CourseAudit',
  props: {
    titleInfo: {
      type: Object,
      required: true
    },
    formBase: {
      type: Object,
      required: true
    }
  },
  data() {
    return {
      dialogFormVisible: false,
      // 表单验证
      ruleInline: {
        auditMind: [{ required: true, message: '审核意见不能为空', trigger: 'blur' }]
      }
    }
  },
  computed: {},
  methods: {
    // 弹层显示
    dialogFormV() {
      this.dialogFormVisible = true
    },
    // 弹层隐藏
    dialogFormH() {
      this.dialogFormVisible = false
    },
    // 审核通过
    agree(auditStatus) {
      this.formBase.auditStatus = this.NET.APPROVED
      this.$refs['dataForm'].validate(async valid => {
        if (valid) {
          this.dialogFormH()
          let data = {
            ...this.formBase
          }
          if (this.formBase.courseBaseId) {
            await approve(data).then(() => {
              this.$emit('audit')
            })
          }
        } else {
          this.$message.error('*号为必填项!')
        }
      })
    },
    // 拒绝通过
    refuse(auditStatus) {
      this.formBase.auditStatus = this.NET.AIDIT_NOT_APPROVED
      this.$refs['dataForm'].validate(async valid => {
        if (valid) {
          this.dialogFormH()
          let data = {
            ...this.formBase
          }
          if (this.formBase.courseBaseId) {
            await approve(data).then(() => {
              this.$emit('audit')
            })
          }
        } else {
          this.$message.error('*号为必填项!')
        }
      })
    }
  },
  // 挂载结束
  mounted: function() {},
  // 创建完毕状态
  created() {
  },
  // 组件更新
  updated: function() {}
}
</script>
<style>
.el-form--label-left .el-form-item__label {
  text-align: right;
}
.el-form-item--medium {
  margin-bottom: 22px;
}
.el-dialog{
  width: 20%;
}
.el-dialog__footer {
  /* text-align: right; */
}
</style>
